#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

namespace ae86 {
	const int bufl = 1 << 15;
	char buf[bufl], *s = buf, *t = buf;
	inline int fetch() {
		if (s == t) { t = (s = buf) + fread(buf, 1, bufl, stdin); if (s == t) return EOF; }
		return *s++;
	}
	inline int read() {
		int a = 0, c = fetch();
		while (!isdigit(c)) c = fetch();
		while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
		return a;
	}
}
using ae86::read;

const int N = 4e4+10;
const int M = 2e5+10;
const int LL = 201;

int ans[M],q1[M],q2[M],f[N][LL];
int l[M],r[M],t[M],id[M],h[N],w[N],n,m,L;

void solve(int *p,int len,int xl,int xr){
	if(xl == xr){
		for(int i = 0;i < len;i++) ans[p[i]] = (t[p[i]] < h[xl]) ? 0 : w[xl];
		return;
	}
	int mid = xl+xr>>1; int t1 = 0,t2 = 0;
	for(int i = 0;i < h[mid];i++) f[mid][i] = 0; for(int i = h[mid];i < L;i++) f[mid][i] = w[mid];
	for(int i = mid-1;i >= xl;i--){
		for(int j = 0;j < h[i];j++) f[i][j] = f[i+1][j];
		for(int j = h[i];j < L;j++) f[i][j] = max(f[i+1][j],f[i+1][j-h[i]]+w[i]);
	}int m1 = mid+1;
	for(int i = 0;i < h[m1];i++) f[m1][i] = 0; for(int i = h[m1];i < L;i++) f[m1][i] = w[m1];
	for(int i = mid+2;i <= xr;i++){
		for(int j = 0;j < h[i];j++) f[i][j] = f[i-1][j];
		for(int j = h[i];j < L;j++) f[i][j] = max(f[i-1][j],f[i-1][j-h[i]]+w[i]);
	}
	for(int i = 0;i < len;i++){
		int x = p[i],lx = l[x],rx = r[x],tx = t[x];
		if(lx <= mid && rx > mid) for(int j = 0;j <= tx;j++) ans[x] = max(ans[x],f[lx][j]+f[rx][tx-j]);
		else if(rx <= mid) q1[t1++] = x;
		else q2[t2++] = x;
	}
	memcpy(p,q1,t1<<2); memcpy(p+t1,q2,t2<<2); solve(p,t1,xl,mid); solve(p+t1,t2,mid+1,xr);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= n;i++) h[i] = in; for(int i = 1;i <= n;i++) w[i] = in;
	for(int i = 0;i < m;i++) l[i] = in,r[i] = in,t[i] = in,id[i] = i,L = max(L,t[i]);
	L++; solve(id,m,1,n);
	for(int i = 0;i < m;i++) printf("%d\n",ans[i]);
	return 0;
}
